package io.github.fb513.api.controller;

import io.github.fb513.api.config.Login;
import io.github.fb513.api.facade.UserFacade;
import io.github.fb513.api.model.CommonResp;
import io.github.fb513.api.model.request.LoginReq;
import io.github.fb513.api.model.request.UserReq;
import io.github.fb513.api.model.response.UserInfoResp;
import io.github.fb513.api.util.RespUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserFacade userFacade;

    @PostMapping("/login")
    public CommonResp<?> generateUserToken(@RequestBody LoginReq loginReq) {
        return RespUtils.success(userFacade.generateUserToken(loginReq));
    }

    @PostMapping("/registry")
    public CommonResp<?> registry(@RequestBody List<UserReq> reqList) {
        userFacade.saveUserBatch(reqList);
        return RespUtils.success();
    }

    @GetMapping("/info")
    public CommonResp<UserInfoResp> getUserInfo(@Login Long userId) {
        return RespUtils.success(userFacade.getUserInfo(userId));
    }
}
